Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaks to eth signer #1526

Merged
merged 6 commits into from
Apr 12, 2024
Merged

Tweaks to eth signer #1526

merged 6 commits into from
Apr 12, 2024

Conversation

jsdw
Copy link
Collaborator

@jsdw jsdw commented Apr 12, 2024

@ryanleecode I finally got to having a pass over #1501 and thought I'd just suggest tweaks in the form of a branch! Lemme know what you reckon, and if all good then we can merge this into your PR and I reckon it's good to go :)

The tweaks:

  • Put behind unstable flag for now
  • Test in CI
  • Separate DerivationPath so that people can configure it more arbitrarily.
  • A couple of misc tweaks

@jsdw jsdw changed the base branch from master to feat/signer/eth April 12, 2024 13:27

# Pick the signer implementation(s) you need by enabling the
# corresponding features. Note: I had more difficulties getting
# ecdsa compiling to WASM on my mac; following this comment helped:
# https://github.com/rust-bitcoin/rust-bitcoin/issues/930#issuecomment-1215538699
sr25519 = ["schnorrkel"]
ecdsa = ["secp256k1"]
eth = ["keccak-hash", "secp256k1", "bip32"]
unstable-eth = ["keccak-hash", "ecdsa", "secp256k1", "bip32"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We pull in the ecdsa::Keypair/sign/verify for instance, so need to ensure this stuff exists too :)

InvalidDerivationIndex(bip32::Error),
/// Invalid phrase.
#[display(fmt = "Cannot parse phrase: {_0}")]
InvalidPhrase(bip39::Error),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We weren't using this error anywhere

Comment on lines +36 to +37
#[cfg(feature = "unstable-eth")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-eth")))]
Copy link
Collaborator Author

@jsdw jsdw Apr 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Niklas suggested we could mark this unstable for now, which I think is a good idea just so that I don't need to worry about it being perfect just yet :) Maybe we find we need t osupport some other things to make this more useful or whatever.

impl Default for Derivation {
fn default() -> Self {
Self::Soft
impl DerivationPath {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the derivation path stuff to a separate struct so that we can accept arbitrary derivation strings and have a couple of nice helpers for "common" things

@jsdw jsdw changed the title Jsdw unstable eth tweaks Tweaks to eth signer Apr 12, 2024
@jsdw jsdw changed the base branch from feat/signer/eth to master April 12, 2024 13:47
@jsdw jsdw changed the base branch from master to feat/signer/eth April 12, 2024 13:48
Copy link
Contributor

@ryanleecode ryanleecode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great. needs a test for the empty derivation path and then its ready to go

signer/src/eth.rs Outdated Show resolved Hide resolved
signer/src/eth.rs Show resolved Hide resolved

// TODO: Currently, we use bip32 to derive private keys which under the hood uses
// the Rust k256 crate. We _also_ use the secp256k1 crate (which is very similar).
// It'd be great if we could 100% use just one of the two crypto libs. bip32 has
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's open a PR to the bip32 crate to update the secp256k1 crate then :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I almost did this hehe, but yup definitely; I think when this merges we can open an issue in Subxt to avoid thedupe crates and then go from there :)

@jsdw
Copy link
Collaborator Author

jsdw commented Apr 12, 2024

Ok, I added a test using some of the vectors in BIP39; these compare mnemonic + password vs seed.

In the process of doing this, I realised that our from_seed functions were a lie; they were actually "from secret key bytes". So I renamed them to from_secret_key_bytes and added a proper from_seed function here, which is then used in the new tests.

CI isn't running but we'll spot any issues once it merges with the other branch I guess!

@ryanleecode ryanleecode marked this pull request as ready for review April 12, 2024 16:53
@ryanleecode ryanleecode requested review from a team as code owners April 12, 2024 16:53
@ryanleecode ryanleecode merged commit 430b001 into feat/signer/eth Apr 12, 2024
1 check passed
@ryanleecode ryanleecode deleted the jsdw-unstable-eth-tweaks branch April 12, 2024 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants